package com.myphoto.base.util;

import com.myphoto.base.enumtype.MsgEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

//Swggger接口文档需要的统一返回类
@ApiModel
public class R<T>{

    @ApiModelProperty(notes = "成功标识",value = "成功标识（Y：成功 N：失败)")
	private String flag;
	@ApiModelProperty(value = "描述信息")
	private String message;
	@ApiModelProperty(value = "业务数据")
	private T data;

	public R(){

	}

	public static R success(){
		R ret = new R();
		ret.setFlag("Y");
		ret.setMessage(MsgEnum.OPRATE_SUCCESS.getMsg());
		return ret;
	}

	public static R success(MsgEnum msgEnum){
		R ret = new R();
		ret.setFlag("Y");
		ret.setMessage(msgEnum.getMsg());
		return ret;
	}

	public static R success(String message){
		R ret = new R();
		ret.setFlag("Y");
		ret.setMessage(message);
		return ret;
	}

	public static R success(String message, Object data){
		R ret = new R();
		ret.setFlag("Y");
		ret.setMessage(message);
		ret.setData(data);
		return ret;
	}

	public static R success(MsgEnum msgEnum, Object data){
		R ret = new R();
		ret.setFlag("Y");
		ret.setMessage(msgEnum.getMsg());
		ret.setData(data);
		return ret;
	}

	public static R error(){
		R ret = new R();
		ret.setFlag("N");
		ret.setMessage("操作失败！");
		return ret;
	}

	public static R error(String message){
		R ret = new R();
		ret.setFlag("N");
		ret.setMessage(message);
		return ret;
	}

	public static R error(MsgEnum msgEnum){
		R ret = new R();
		ret.setFlag("N");
		ret.setMessage(msgEnum.getMsg());
		return ret;
	}

	public static R error(String message, Object data){
		R ret = new R();
		ret.setFlag("N");
		ret.setMessage(message);
		ret.setData(data);
		return ret;
	}

	public static R error(MsgEnum msgEnum, Object data){
		R ret = new R();
		ret.setFlag("N");
		ret.setMessage(msgEnum.getMsg());
		ret.setData(data);
		return ret;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

}